<template>
  <div>
    {{elcfg1}}
    <hr />
    {{optcfg}}
    <el-upload v-bind="elcfg1" :action="action" class="upload-demo" :on-success="success">
      <i class="el-icon-upload"></i>
      <!-- <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div> -->
    </el-upload>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name:"myUpload",
  props:['elcfg','optcfg'],
  computed:{
    action(){
      if(this.elcfg && this.elcfg.action){
        return this.elcfg.action
      }
      return ""
    }
  },
  methods:{
    success(res, file) {
        console.log(res);
        // console.log(file);
        var r=res[this.optcfg.resultField]
        console.log(r);
        this.$emit('input',r)
    },
  },
  watch:{
    elcfg:{
      deep:true,
      immediate:true,
      handler(n,o){
        if(n==undefined) return
        this.elcfg1=n
        if (this.elcfg1.data!=null && this.elcfg1.data!=undefined){
          if(this.elcfg1.data=="") this.elcfg1.data={}
          else this.elcfg1.data=JSON.parse(this.elcfg1.data)
        }
        if (this.elcfg1.headers!=null && this.elcfg1.headers!=undefined){
          if(this.elcfg1.headers=="") this.elcfg1.headers={}
          else this.elcfg1.headers=JSON.parse(this.elcfg1.headers)
        }
      }
    }
  },
  data(){
    return {
      elcfg1:{}
    }
  }
}
</script>

<style>

</style>